package com.example.ziru.mapper;

import com.example.ziru.entity.Rooms;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoomsMapper {

    //查找所有
    @Select("select * from rooms")
    List<Rooms> getAllRooms();

    //按价格升序
    @Select("SELECT * FROM rooms ORDER BY roomPrice asc")
    List<Rooms> queryRoomsByPriceAsc();

    //按价格降序
    @Select("SELECT * FROM rooms ORDER BY roomPrice desc")
    List<Rooms> queryRoomsByPriceDesc();

    //按面积降序
    @Select("SELECT * FROM rooms ORDER BY roomArea desc")
    List<Rooms> queryRoomsByAreaDesc();
    //按面积升序
    @Select("SELECT * FROM rooms ORDER BY roomArea asc")
    List<Rooms> queryRoomsByAreaAsc();
    //模糊查询
    @Select("select * from rooms where roomName like '%${str}%' OR roomLocation like '%${str}%' OR areaLocation like '%${str}%' OR subway like '%${str}%'")
    List<Rooms> select(String str);

    @Select("select * from rooms where roomId = #{id}")
    Rooms queryRoomsById(int id);

    //随机抽三个数据
    @Select("SELECT * FROM rooms order by rand() limit 3")
    List<Rooms> queryRoomsByRand();

    @Select("select titleName from roomtitle where roomId = #{id}")
    List<String> queryTileByRoomId(int id);
}
